﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SpringGraph.Controls;
using SpringGraphExample.Entities;

namespace SpringGraphExample.TemplateSelectors
{
    public class CustomTemplateSelector : Control, IControlTemplateSelector
    {
        #region Templates
        public ControlTemplate ProductTemplate
        {
            get
            {
                return (ControlTemplate)GetValue(ProductTemplateProperty);
            }
            set
            {
                SetValue(ProductTemplateProperty, value);
            }
        }

        public static readonly DependencyProperty ProductTemplateProperty = DependencyProperty.Register(
            "ProductTemplate", typeof(ControlTemplate), typeof(CustomTemplateSelector), new PropertyMetadata(null));

        public ControlTemplate CategoryTemplate
        {
            get
            {
                return (ControlTemplate)GetValue(CategoryTemplateProperty);
            }
            set
            {
                SetValue(CategoryTemplateProperty, value);
            }
        }

        public static readonly DependencyProperty CategoryTemplateProperty = DependencyProperty.Register(
            "CategoryTemplate", typeof(ControlTemplate), typeof(CustomTemplateSelector), new PropertyMetadata(null));

        #endregion

        public ControlTemplate SelectTemplate(object dataContext)
        {
            ControlTemplate template = null;

            if (dataContext is Product)
                template = ProductTemplate;
            else if (dataContext is Category)
                template = CategoryTemplate;

            return template;
        }
    }
}
